# Maintainer: Guillaume ALAUX <guillaume@archlinux.org>
# Contributor: Andrea Scarpino <andrea@archlinux.org>
# Contributor: Leif Warner <abimelech@gmail.com>

pkgname=sbt
epoch=1
pkgver=1.8.1
pkgrel=1
pkgdesc='The interactive build tool'
arch=('any')
url='https://www.scala-sbt.org/'
license=('BSD')
depends=('java-runtime-headless' 'sh')
IFS='.' read -a _pkgver <<< "${pkgver}"
_majorver=${_pkgver[0]}.x
install=sbt.install
source=(https://github.com/${pkgname}/${pkgname}/releases/download/v${pkgver}/${pkgname}-${pkgver}.tgz{,.asc}
        LICENSE)
validpgpkeys=('2EE0EA64E40A89B84B2DF73499E82A75642AC823') # sbt build tool
sha512sums=('7673f0670f00f24f41ee36481f54827c5ae771866ebf3a6f7a9efa6891bff8c6d315368f760ac574ceb2ef7b2484464ead21030f57047b1bc7859ab79b4254da'
            'SKIP'
            '49fefd36f8e3e796efd2b95aec76781832f64163445b6ebba624e385446bcbd308e27a82770b5e7b1ce7d4cd406d771549f0a121f1310611c92b3e15bff209d0')
backup=(etc/${pkgname}/sbtopts)

package() {
  cd "${pkgname}"

  mkdir -p "${pkgdir}"/usr/share/${pkgname}
  cp -r bin "${pkgdir}"/usr/share/${pkgname}
  rm "${pkgdir}"/usr/share/${pkgname}/bin/*{.bat,.exe,-darwin}
  chmod -x "${pkgdir}"/usr/share/${pkgname}/bin/*
  chmod +x "${pkgdir}"/usr/share/${pkgname}/bin/{sbt,sbtn-x86_64-pc-linux}
  mkdir -p "${pkgdir}"/usr/bin
  ln -s /usr/share/${pkgname}/bin/sbt "${pkgdir}"/usr/bin/sbt

  mkdir -p "${pkgdir}/etc"
  cp -r conf "${pkgdir}"/etc/${pkgname}
  rm "${pkgdir}"/etc/${pkgname}/sbtconfig.txt
  ln -s /etc/${pkgname} "${pkgdir}"/usr/share/${pkgname}/conf

  install -D "${srcdir}"/LICENSE -t "${pkgdir}"/usr/share/licenses/${pkgname}
}
